package JAVACORE_TRAINING.ADVANCED.SWING;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class TextfieldTutorial extends JFrame implements ActionListener {
	private JTextField jTextField;
	private JButton jButton;

	public TextfieldTutorial() {
		this.setTitle("Textfield tutorial");
		this.setSize(300, 400);
		this.setLocation(300, 100);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		jTextField = new JTextField();
		add(jTextField, "North", 0);
		jButton = new JButton("Get Value");
		add(jButton, "South", 0);
		jButton.addActionListener(this);

	}

@Override
	public void actionPerformed(ActionEvent e) {
		if ((JButton) e.getSource() == jButton) {

			JOptionPane.showMessageDialog(null, jTextField.getText());
			jTextField.setText("abc");
		}
	}

	public static void main(String[] args) {
		TextfieldTutorial textfieldTutorial = new TextfieldTutorial();
		textfieldTutorial.setVisible(true);
	}

}
